package com.sxt.oa;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;
import org.springframework.web.servlet.view.BeanNameViewResolver;
import org.springframework.web.servlet.view.InternalResourceView;

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.sxt.oa.controller")
public class SpringMVCConfig implements WebMvcConfigurer {

    /**
     * 该视图对象配合用户登录时，显示登录页面
     *
     * @return
     */
    @Bean
    public InternalResourceView login() {
        InternalResourceView view = new InternalResourceView();
        view.setUrl("/index.jsp");
        return view;
    }

    public void configureViewResolvers(ViewResolverRegistry registry) {
        // 根据逻辑视图名从容器中查找同名的Bean对象(视图)
        BeanNameViewResolver beanNameViewResolver = new BeanNameViewResolver();
        beanNameViewResolver.setOrder(3);
        registry.viewResolver(beanNameViewResolver);

        registry.jsp("/WEB-INF/", ".jsp");
    }

    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/top").setViewName("top");
        registry.addViewController("/left").setViewName("left");
        registry.addViewController("/mainfrm").setViewName("mainFrm");
        registry.addViewController("/main").setViewName("main");
        registry.addViewController("/unperm").setViewName("unperm");
    }

    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }
}
